import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

public class o {
    @Test
    public void readTest() {
        HashMap<String, Integer> hashMap = new HashMap();
        String filePath = "C:\\Users\\Buddy\\Desktop\\B.txt";
        File file = new File(filePath);
        try (BufferedReader reader = new BufferedReader(new FileReader(file));) {
            String line;
            String pre = null;
            while ((line = reader.readLine()) != null) {
//                sbf.append(line);
                if (line.trim().length() > 0) {
                    String[] strs = line.split(" ");
                    for (int i = 0; i < strs.length; i++) {
                        String type = strs[i].trim();
                        if (type.length() > 0) {
                            if (type.equals("连续")) {
                                type = pre;
                            } else {
                                pre = type;
                            }
                            Integer count = 0;
                            if (hashMap.containsKey(type)) {
                                count = hashMap.get(type);
                            }
                            hashMap.put(type, count + 1);
                        }
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
//        int i = 0;
//        assert str != null;
//        String pre = "";
//        while (i < str.length()) {
//            String type = str.substring(i, i + 2);
//            if (type.equals("边中") || type.equals("擦伤")){
//                type = str.substring(i,i+3);
//                i = i + 2;
//            }else{
//                i=i+2;
//            }
//            System.out.println(type);
//            if (type.equals("连续")){
//                type = pre;
//            }else{
//                pre = type;
//            }
//            Integer count = 0;
//            if (hashMap.containsKey(type)){
//                count = hashMap.get(type);
//            }
//            hashMap.put(type,count+1);
//        }
        hashMap.forEach((key,value)->{
            System.out.println(key+" "+value);
        });
    }
}
